Ansiable Preparation

1. 控制端生成密钥

ssh-keygen  -N "" -b 4096 -t rsa

2. 添加密钥到测试服务器中

默认信任 主机联通

但在新版本中Ansible的sudo命令废弃,改为--become或-b,如上命令需改为如下:

 ansible dbservers -b -m command -a 'hostname' -vvv
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.10.167
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.10.168
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.10.169

3. 编辑inventory 文件

cat >> /etc/ansible/hosts << EOF
192.168.10.167
192.168.10.168
192.168.10.169

4. 测试ping 模块

ansible all -m ping 
ansible dbservers -m ping